<?php
/**
 *+------------------
 * Lflow
 *+------------------
 * Copyright (c) 2023~2030 gitee.com/liu_guan_qing All rights reserved.本版权不可删除，侵权必究
 *+------------------
 * Author: Mr.April(405784684@qq.com)
 *+------------------
 */
declare (strict_types=1);

namespace lflow\access\dialect;

use lflow\access\Page;

/**
 * Mysql分页处理类
 *
 * @author Mr.April
 * @since  1.0
 */
class MySqlDialect implements Dialect
{

    /**
     * mysql分页通过limit实现
     *
     * @param string             $sql
     * @param \lflow\access\Page $page
     *
     * @return string
     */
    public function getPageSql(string $sql, Page $page): string
    {
        $pageSql = $sql;
        $start   = ($page->getPageNo() - 1) * $page->getPageSize();
        return $pageSql . " limit " . $start . ", " . $page->getPageSize();
    }
}